package com.nnnu.orange.controller.user;


import com.nnnu.orange.constant.MessageConstants;
import com.nnnu.orange.pojo.dto.*;
import com.nnnu.orange.pojo.entity.Comments;
import com.nnnu.orange.pojo.vo.CommentsVo;
import com.nnnu.orange.result.PageResult;
import com.nnnu.orange.result.Result;
import com.nnnu.orange.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 存储图书评论的详细信息 前端控制器
 * </p>
 *
 * @author zk
 * @since 2024-11-07
 */
@RestController("userCommentsController")
@RequestMapping("/user/comments")
@Slf4j
@Api(tags = "用户端图书评论相关接口")
@RequiredArgsConstructor
public class CommentsController {

    private final ICommentsService iCommentsService;


    /**
     * 分页查询图书评论
     *
     * @param queryDto dto
     * @return 分页列表
     */
    @GetMapping
    @ApiOperation("分页查询图书评论")
    public Result<?> list(CommentQueryDto queryDto) {
        log.info("分页查询图书评论:{}", queryDto);
        return Result.success(iCommentsService.list(queryDto), MessageConstants.SELECT_OK);
    }

    /**
     * 用户新增图书评论
     *
     * @param commentDto dto
     * @return 提示
     */
    @PostMapping
    @ApiOperation("用户新增图书评论")
    public Result<String> save(@RequestBody @Valid CommentDto commentDto) {
        log.info("用户新增图书评论:{}", commentDto);
        iCommentsService.save(commentDto);
        return Result.success(MessageConstants.ADD_OK);
    }
}
